package demo2;

class Animal {
    public String name;
    public int age;

    public Animal(String name) {
        this.name = name;
    }

    public void eat() {
        System.out.println(this.name + "吃饭!");
    }

    // 跑、飞、游泳不能写到这里
}

interface IFlying {
    void fly();
}

interface IRunning {
    void run();
}

interface ISwimming {
    void swim();
}

class Dog extends Animal implements IRunning, ISwimming{

    public Dog(String name) {
        super(name);
    }

    @Override
    public void run() {
        System.out.println(this.name + "is dog, 正在跑！");
    }

    @Override
    public void swim() {
        System.out.println(this.name + "is dog, 正在游泳！");
    }
}

class Cat extends Animal implements IRunning {

    public Cat(String name) {
        super(name);
    }

    @Override
    public void run() {
        System.out.println(this.name + "is cat, 正在跑");
    }
}

class Duck extends Animal implements IRunning, ISwimming, IFlying {

    public Duck(String name) {
        super(name);
    }
    // ctrl + i 快速实现重写
    @Override
    public void fly() {

    }

    @Override
    public void run() {

    }

    @Override
    public void swim() {

    }
}

public class Test {

    public static void walk(IRunning iRunning) {
        iRunning.run();
    }

    public static void main(String[] args) {
        Cat cat = new Cat("咪咪");
        //cat.run();
        walk(cat);

        Dog dog = new Dog("旺财");
        //dog.run();
        walk(dog);
    }
}
